package com.akgroup.ticketease.member.service.impl;

import com.akgroup.common.util.SnowUtil;
import com.akgroup.ticketease.member.domain.Member;
import com.akgroup.ticketease.member.mapper.MemberMapper;
import com.akgroup.ticketease.member.req.MemberRegisterReq;
import com.akgroup.ticketease.member.service.MemberService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author Lenovo
* @description 针对表【member(会员)】的数据库操作Service实现
* @createDate 2024-04-23 23:48:42
*/
@Service
public class MemberServiceImpl extends ServiceImpl<MemberMapper, Member>
    implements MemberService {

    @Autowired
    private MemberMapper memberMapper;

    @Override
    public long register(MemberRegisterReq req){
        String mobile = req.getMobile();
        QueryWrapper<Member> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("mobile",mobile);
        Long count = memberMapper.selectCount(queryWrapper);
        if(count>0) {
            throw new RuntimeException("手机号已注册");
        }
        Member member = new Member();
        member.setId(SnowUtil.getSnowflakeNextId());
        member.setMobile(mobile);
        memberMapper.insert(member);
        return member.getId();
    }
}




